﻿using Commons;

namespace Switch
{
    internal class SwitchTest1
    {
        public void Test1()
        {
            int res = 0, a = 10, b = 2;
            OperatorType operatorType = OperatorType.加;
            switch (operatorType)
            {
                case OperatorType.加:
                    res = a + b;
                    break;
                case OperatorType.减:
                    res = a - b;
                    break;
                case OperatorType.乘:
                    res = a * b;
                    break;
                case OperatorType.除:
                    // 需要增加判断b!=0;
                    if (b == 0)
                    {
                        //b = 1;
                        throw new Exception("被除数不能为0");
                    }
                    res = a / b;
                    break;
            }
            Console.WriteLine($"运算结果:{res}");
        }
    }
}
